package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 护理项目Controller类
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingProjectVo> nursingProjectPageInfo = nursingProjectService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(nursingProjectPageInfo);
    }

    @PostMapping
    @ApiOperation(value = "新增护理项目", notes = "传入护理项目信息，返回添加结果")
    public ResponseResult addNursingProject(@RequestBody  NursingProjectVo nursingProjectVo) {
        nursingProjectService.addNursingProject(nursingProjectVo);
        return ResponseResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据护理项目id查询护理项目信息", notes = "传入护理项目id")
    public ResponseResult getNursingProjectById(
            @ApiParam(value = "护理项目ID", required = true)
            @PathVariable("id") Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.getNursingProjectById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    @PutMapping()
    @ApiOperation(value = "修改护理项目信息", notes = "传入护理项目信息，返回修改结果")
    public ResponseResult modifyNursingProject(
            @RequestBody NursingProjectVo nursingProjectVo) {
        nursingProjectService.modifyNursingProject(nursingProjectVo);
        return ResponseResult.success();
    }

    @PutMapping("{id}/status/{status}")
    @ApiOperation(value = "修改护理项目状态", notes = "传入护理项目id和状态，返回修改结果")
    public ResponseResult modifyNursingProjectStatus(
            @ApiParam(value = "护理项目ID", required = true)
            @PathVariable("id") Long id,
            @ApiParam(value = "状态：0-禁用，1-启用", required = true)
            @PathVariable("status") Integer status) {
        nursingProjectService.modifyNursingProjectStatus(id, status);
        return ResponseResult.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除护理项目", notes = "传入护理项目id，返回删除结果")
    public ResponseResult deleteNursingProject(
            @ApiParam(value = "护理项目ID", required = true)
            @PathVariable Long id) {
        nursingProjectService.deleteNursingProject(id);
        return ResponseResult.success();
    }

    @GetMapping("/all")
    @ApiOperation(value = "查询所有护理项目", notes = "返回护理项目列表")
    public ResponseResult getAllNursingProjects() {
        return ResponseResult.success(nursingProjectService.getAllNursingProjects());
    }
}